﻿/*include:js\declare*/
//鼠标覆盖菜单	<div id="YYY"></div><div mousemenu="{MenuId:'YYY',IsDisplay:1,Type:'Bottom',Top:5,Left:-5}" id="XXX"></div>
(function(){
var MouseMenu=function()
	{
	this.GetArgument(arguments[0],{Id:null,Event:null,MenuId:null,SkinView:null,ShowViewFunctionName:null,OnStart:null,Timeout:100,Type:null,Top:null,Left:null,OverClassName:null,OutClassName:null,IsCheckScroll:1,IsShow:1,IsMove:1,IsMouseMove:0,OnMove:null,OnShowed:null,ZIndex:1});
	this.OnStart=fastCSharp.Event().Add(this.OnStart);
	this.OnShowed=fastCSharp.Event().Add(this.OnShowed);
	this.HideFunction=fastCSharp.ThisFunction(this,this.Hide);
	this.OnMove=fastCSharp.Event().Add(this.OnMove);
	this.MouseOutFunction=fastCSharp.ThisFunction(this,this.MouseOut);
	this.Start(this.Event||{IsGetOnly:1});
	};
(fastCSharp.Functions.MouseMenu=MouseMenu).Inherit(fastCSharp.BaseFunction,{
Start:function(Event)
	{
	if(!Event.IsGetOnly)
		{
		this.OnStart(this);
		var Element=fastCSharp.$Id(this.Id),Input=Element.Element();
		if(Input!=this.Element)
			{
			this.Element=Input;
			Element.AddEvent('mouseout',this.MouseOutFunction);
			if(this.IsMouseMove)	Element.AddEvent('mousemove',fastCSharp.ThisEvent(this,this.ReShow));
			this.CheckMenuParameter(1);
			}
		this.ClearInterval();
		this.IsOver=1;
		this.Show(Event);
		}
	},
CheckMenuParameter:function(IsStart)
	{
	var Element=fastCSharp.$Id(this.MenuId),Parameter=Element.Get('mousemenu');
	if(Parameter!=null)
		{
		var Id=eval('('+Parameter+')').Id;
		if(Id!=this.Id)
			{
			Parameter=null;
			var Menu=fastCSharp.GetMouseMenu(Id);
			if(Menu){
				Menu.Remove();
				Element.Set('mousemenu','{Id:"'+this.Id+'"}');
				return;
				}
			}
		}
	if(IsStart)
		{
		if(Parameter==null)	Element.Set('mousemenu','{Id:"'+this.Id+'"}');
		Element.AddEvent('mouseout',this.MouseOutFunction);
		}
	},
Show:function(Event)
	{
	var Menu=fastCSharp.$Id(this.MenuId),Skin;
	if(this.IsMove)	Menu.Css('position','absolute').Css('zIndex',fastCSharp.ZIndex+this.ZIndex);
	if(this.SkinView)	Skin=fastCSharp.Skins[this.MenuId];
	var IsShow=this.ShowViewFunctionName==null||this.SkinView[this.ShowViewFunctionName]();
	if(Skin&&this.ShowView!=this.SkinView)
		{
		this.ShowView=this.SkinView;
		if(IsShow)	Skin.Show(this.SkinView);
		}
	if(this.IsShow&&IsShow)	Menu.Display(1);
	var Element=fastCSharp.$Id(this.Id);
	if(this.OutClassName)	Element.Class(this.OutClassName,1);
	if(this.OverClassName)	Element.Class(this.OverClassName);
	if(this.IsMove)	this.ReShow(Event,Element);
	this.OnShowed();
	},
MouseOut:function()
	{
	this.IsOver=0;
	this.ClearInterval();
	this.HideInterval=setTimeout(this.HideFunction,this.Timeout);
	},
ClearInterval:function()
	{
	if(this.HideInterval)
		{
		clearTimeout(this.HideInterval);
		this.HideInterval=0;
		}
	},
Hide:function()
	{
	this.ClearInterval();
	var Element=fastCSharp.$Id(this.Id);
	if(this.OverClassName)	Element.Class(this.OverClassName,1);
	if(this.OutClassName)	Element.Class(this.OutClassName);
	if(this.IsShow)	this.$Id(this.MenuId).Display(0);
	this.ShowView=null;
	},
Remove:function()
	{
	this.ClearInterval();
	this.ShowView=null;
	var Element=fastCSharp.$Id(this.Id);
	Element.DeleteEvent('mouseout',this.MouseOutFunction);
	fastCSharp.$Id(this.MenuId).Set('mousemenu','').DeleteEvent('mouseout',this.MouseOutFunction);
	this.Element=null;
	},
CheckScroll:function(Left,Top,XY)
	{
	if(this.Left)	Left+=this.Left;
	if(this.Top)	Top+=this.Top;
	var Menu=fastCSharp.$Id(this.MenuId);
	if(this.IsCheckScroll)
		{
		var ScrollLeft=fastCSharp.$ScrollLeft(),ScrollTop=fastCSharp.$ScrollTop();
		if(XY)	{
			var Width=Menu.Width(),Height=Menu.Height();
			if(Width)
				{
				var ClientWidth=fastCSharp.$Width()+ScrollLeft;
				if(ClientWidth>XY.Left&&Left>(ClientWidth-=Width))	Left=ClientWidth;
				}
			if(Height)
				{
				var ClientHeight=fastCSharp.$Height()+ScrollTop;
				if(ClientHeight>XY.Top&&Top>(ClientHeight-=Height))	Top=ClientHeight;
				}
			}
		if(Left<ScrollLeft)	Left=ScrollLeft;
		if(Top<ScrollTop)	Top=ScrollTop;
		}
	Menu.ToXY(Left,Top);
	},
ReShow:function(Event,Element)
	{
	this.OnMove(Event,this);
	this['To'+(this.Type||'Mouse')](Event,Element);
	},
ToMouse:function(Event,Element)
	{
	this.CheckScroll(Event.clientX,Event.clientY);
	},
ToTopLeft:function(Event,Element)
	{
	var XY=Element.XY();
	this.CheckScroll(XY.Left,XY.Top-fastCSharp.$Id(this.MenuId).Height(),XY);
	},
ToTopRight:function(Event,Element)
	{
	var Menu=fastCSharp.$Id(this.MenuId),XY=Element.XY();
	this.CheckScroll(XY.Left+Element.Width()-Menu.Width(),XY.Top-Menu.Height(),XY);
	},
ToTop:function(Event,Element)
	{
	var Menu=fastCSharp.$Id(this.MenuId),XY=Element.XY();
	this.CheckScroll(XY.Left+(Element.Width()-Menu.Width())/2,XY.Top-Menu.Height(),XY);
	},
ToBottomLeft:function(Event,Element)
	{
	var XY=Element.XY();
	this.CheckScroll(XY.Left,XY.Top+Element.Height(),XY);
	},
ToBottomRight:function(Event,Element)
	{
	var XY=Element.XY();
	this.CheckScroll(XY.Left+Element.Width()-fastCSharp.$Id(this.MenuId).Width(),XY.Top+Element.Height(),XY);
	},
ToBottom:function(Event,Element)
	{
	var XY=Element.XY();
	this.CheckScroll(XY.Left+(Element.Width()-fastCSharp.$Id(this.MenuId).Width())/2,XY.Top+Element.Height(),XY);
	},
ToLeftTop:function(Event,Element)
	{
	var XY=Element.XY();
	this.CheckScroll(XY.Left-fastCSharp.$Id(this.MenuId).Width(),XY.Top,XY);
	},
ToLeftBottom:function(Event,Element)
	{
	var Menu=fastCSharp.$Id(this.MenuId),XY=Element.XY();
	this.CheckScroll(XY.Left-Menu.Width(),XY.Top+Element.Height()-Menu.Height(),XY);
	},
ToLeft:function(Event,Element)
	{
	var Menu=fastCSharp.$Id(this.MenuId),XY=Element.XY();
	this.CheckScroll(XY.Left-Menu.Width(),XY.Top+(Element.Height()-Menu.Height())/2,XY);
	},
ToRightTop:function(Event,Element)
	{
	var XY=Element.XY();
	this.CheckScroll(XY.Left+Element.Width(),XY.Top,XY);
	},
ToRightBottom:function(Event,Element)
	{
	var XY=Element.XY();
	this.CheckScroll(XY.Left+Element.Width(),XY.Top+Element.Height()-fastCSharp.$Id(this.MenuId).Height(),XY);
	},
ToRight:function(Event,Element)
	{
	var XY=Element.XY();
	this.CheckScroll(XY.Left+Element.Width(),XY.Top+(Element.Height()-fastCSharp.$Id(this.MenuId).Height())/2,XY);
	}
		});
new fastCSharp.Declare('MouseMenu','mouseover','ParameterId');
})();